package com.baidu.androidannotation;

import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
//在fragment里用法与此处类似（把类注解改成@EFragment(R.layout.fragment_test)）

@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {


    @ViewById
    TextView msgTv;
    @ViewById
    TextView titleTv;
    @ViewById
    TextView descTv;
    @ViewById
    Button firstBtn;
    @ViewById
    Button secondBtn;
    @ViewById
    Button thirdBtn;
    @ViewById
    Button forthBtn;

    //该注解方法执行在@ViewById之后,@AfterView注解方法之前
    @AfterInject//execute in mainThread
    public void initData() {
        String version = "123.6.6.6.";
        Toast.makeText(MainActivity.this, "I come back again", Toast.LENGTH_SHORT).show();
    }


    //这个方法在主线程中运行
    @AfterViews//execute in mainThread
    public void initView() {
        msgTv.setText("new messsage");
        titleTv.setText("your birthday");
        descTv.setText("I`ll come soon");
    }

    @Click({R.id.firstBtn, R.id.secondBtn, R.id.thirdBtn, R.id.forthBtn})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.firstBtn:
                toast("first");
                break;
            case R.id.secondBtn:
                toast("second");
                break;
            case R.id.thirdBtn:
                toast("third");
                break;
            case R.id.forthBtn:
                toast("forth");
                break;
        }
    }


    public void toast(String msg) {
        Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
    }
}
